﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Camc.Duct.Configuration;
using Camc.Duct.Web;

namespace Camc.Duct.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class DuctDbContextFactory : IDesignTimeDbContextFactory<DuctDbContext>
    {
        public DuctDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<DuctDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true);

            DuctDbContextOptionsConfigurer.Configure(builder, 
				configuration.GetConnectionString(DuctConsts.ConnectionStringName));

            return new DuctDbContext(builder.Options);
        }
    }
}